
import gui.std.AppChooser;
import gui.std.GClient;
import gui.std.GServer;
import gui.std.ImageChooser;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import util.Constants;
import app.User;

public class Main {

	public static void main(String[] args) {
		
		final AppChooser chooser = new AppChooser();
		
		chooser.setAction(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ((chooser.getMode() == Constants.SERVER) || (!chooser.getUser().isEmpty() && !chooser.getServer().isEmpty()))
					chooser.setVisible(false);
				else
					chooser.setInfoMsg(" Not connected!  ");
			}
		});
		
		//wait
		while (chooser.isVisible()){
			try {
				Thread.sleep(50);
			}
			catch (InterruptedException e){e.printStackTrace();}
		};
		
		if (chooser.getMode() == Constants.SERVER){
			@SuppressWarnings("unused")
			GServer server = new GServer();
		}
		else {
			ImageChooser ich = new ImageChooser();
			
			//wait
			while (ich.isVisible()) {
				try {
					Thread.sleep(50);
				}
				catch (InterruptedException e){e.printStackTrace();}
			};
			
			User user = new User(chooser.getUser());
			user.setPathImage(ich.getPathImage());
			
			@SuppressWarnings("unused")
			GClient client = new GClient(chooser.getServer(), user);
		}
	}
}